#include <57header.h>

int main(int argc,char*argv[])
{

    int pipe_fd[2];
    pipe(pipe_fd);

    if(fork() == 0){
        // 子进程
        // 读 -> 0读
        close(pipe_fd[1]);

        int net_fd = 0;
        read(pipe_fd[0], &net_fd, sizeof(int));

        printf("net_fd: %d \n", net_fd);

        int ret = send(net_fd, "hello", 5, 0);
        ERROR_CHECK(ret, -1, "send");

    }else{
        // 父进程
        // 写 -> 1写
        close(pipe_fd[0]);

        int socket_fd = socket(AF_INET, SOCK_STREAM, 0);
        char *port = "8080";
        char *ip = "192.168.106.129";

        struct sockaddr_in sockaddr;
        sockaddr.sin_family = AF_INET;
        sockaddr.sin_port = htons(atoi(port));
        sockaddr.sin_addr.s_addr = inet_addr(ip);


        bind(socket_fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr));

        listen(socket_fd, 10);

        int net_fd = accept(socket_fd, NULL, NULL);

        write(pipe_fd[1], &net_fd, sizeof(int));

    }

    return 0;
}

